import static org.junit.Assert.*;
import junit.framework.TestCase;

import org.junit.Before;
import org.junit.Test;


public class VendingMachineItemTest extends TestCase{
	String itemName1, itemName2, itemName3, itemName4;
	double price1, price2, price3, price4;
	VendingMachineItem vmi1, vmi2, vmi3, vmi4;
	boolean b;
	
	// setting up the test object
	@Before
	public void setUp() throws Exception {
		itemName1 = "Pepsi";
		price1 = 1.50;
		itemName2 = "CokeCole";
		price2 = 1.75;
		itemName3 = "MtnDew";
		price3 = 1.25;
		itemName4 = "SpringWater";
		price4 = 1.00;
		vmi1 = new VendingMachineItem(itemName1, price1);
		vmi2 = new VendingMachineItem(itemName2, price2);
		vmi3 = new VendingMachineItem(itemName3, price3);
		vmi4 = new VendingMachineItem(itemName4, price4);
	}

	@Test
	public void testVendingMachineItem() {
		// testing that an object is created by the constructor using valid parameters
		assertNotNull(new VendingMachineItem(itemName1, price1));
		
		// Here according to the code zero is a valid price for an item, 
		 // but in real price of an item cannot be zero, this might be a bud as there has to be a 
		 // price for an item
		assertNotNull(new VendingMachineItem(itemName1, 0));
		
		// Here is a bug, there is no item and there is a price to the no-item.
		//There should be a check for null in the VendingMachineItem Constructor
		assertNotNull(new VendingMachineItem( null, 10.00));
		
		//this is negative testing for the constructor, testing for the exception when the price is
		// less than zero
		b = true;
		try {
			new VendingMachineItem(itemName1, -0.10);
		} catch (Exception e) {
			assertSame("Price cannot be less than zero", e.getMessage());
			b = false;
		}
		
		assertFalse(b);
	}

	@Test
	public void testGetName() {
		
		// testing the getName method, to verify that the correct name is returned.
		assertSame(itemName1, vmi1.getName());
		assertNotSame(itemName2, vmi1.getName());
		assertNotSame(null, vmi1.getName());
	}

	@SuppressWarnings("deprecation")
	@Test
	public void testGetPrice() {
		//testing the getPrice() method for verifying that the method returns the correct price.
		assertTrue(price1 == vmi1.getPrice());
		assertFalse(price2 == vmi1.getPrice());
	}

}
